<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.0.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.0.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.0.4">


  <link rel="mask-icon" href="/images/logo.svg?v=6.0.4" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '6.0.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  
  <meta name="keywords" content="技术博客,php,java,python,go" />


<meta name="description" content="参考：http://www.fecmall.com/doc/fec-go-guide/develop/cn-1.0/guide-trace-about.htmlhttps://www.runoob.com/mongodb/mongodb-map-reduce.html 系统收集数据后，存入MongoDB，然后使用MongoDB Map Reduce进行数据统计聚合，然后写入ElasticSearc">
<meta property="og:type" content="article">
<meta property="og:title" content="FA 用户数据分析系统学习笔记">
<meta property="og:url" content="http://blog.yunshu168.com/posts/6e943b7a.html">
<meta property="og:site_name" content="树下千云">
<meta property="og:description" content="参考：http://www.fecmall.com/doc/fec-go-guide/develop/cn-1.0/guide-trace-about.htmlhttps://www.runoob.com/mongodb/mongodb-map-reduce.html 系统收集数据后，存入MongoDB，然后使用MongoDB Map Reduce进行数据统计聚合，然后写入ElasticSearc">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-03-10T08:34:49.413Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="FA 用户数据分析系统学习笔记">
<meta name="twitter:description" content="参考：http://www.fecmall.com/doc/fec-go-guide/develop/cn-1.0/guide-trace-about.htmlhttps://www.runoob.com/mongodb/mongodb-map-reduce.html 系统收集数据后，存入MongoDB，然后使用MongoDB Map Reduce进行数据统计聚合，然后写入ElasticSearc">






  <link rel="canonical" href="http://blog.yunshu168.com/posts/6e943b7a.html"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>
  <title>FA 用户数据分析系统学习笔记 | 树下千云</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?f8a99180bb75f49a4b2206cab6e25c50";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <!-- <div class="headband"></div>
<a href="https://github.com/yunshu2009"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a> -->
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">树下千云</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>


  



 </div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.yunshu168.com/posts/6e943b7a.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="云舒">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="树下千云">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">FA 用户数据分析系统学习笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <!--<span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>-->
              
                <!--<span class="post-meta-item-text">发表于</span>-->
              
              <!--<time title="创建于" itemprop="dateCreated datePublished" datetime="2020-02-15T11:06:59+08:00">2020-02-15</time>-->
            

            
            

            
          </span>

          

          
            
          

          
          

          


          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>参考：<br><a href="http://www.fecmall.com/doc/fec-go-guide/develop/cn-1.0/guide-trace-about.html" target="_blank" rel="noopener">http://www.fecmall.com/doc/fec-go-guide/develop/cn-1.0/guide-trace-about.html</a><br><a href="https://www.runoob.com/mongodb/mongodb-map-reduce.html" target="_blank" rel="noopener">https://www.runoob.com/mongodb/mongodb-map-reduce.html</a></p>
<p>系统收集数据后，存入MongoDB，然后使用MongoDB Map Reduce进行数据统计聚合，然后写入ElasticSearch，最后从ElasticSearch中取出数据，传达给vue前端渲染。</p>
<h3 id="数据统计"><a href="#数据统计" class="headerlink" title="数据统计"></a>数据统计</h3><p>首先执行fec-go-shell.go的main函数<br><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="comment">// 初始化log输出，log.Println("---") 输出的内容将输出到globalLog文件里面</span></span><br><span class="line">    log.Println(<span class="string">"------start："</span> + time.Now().String())</span><br><span class="line">    <span class="comment">// 进行验证，将配置中的信息取出来，然后进行jwt处理，然后远程访问。</span></span><br><span class="line">    initialization.InitShellLog()</span><br><span class="line">    <span class="comment">// 进行远程授权验证</span></span><br><span class="line">    <span class="comment">// 脚本执行部分，不再做授权验证，只对服务提供的go入口添加远程验证。</span></span><br><span class="line">    <span class="comment">// verify()</span></span><br><span class="line">    log.SetFlags(log.LstdFlags | log.Llongfile)</span><br><span class="line">    <span class="comment">// 脚本处理，入口函数。</span></span><br><span class="line">    shell.GoShell()</span><br><span class="line">    <span class="comment">// shell.TestEs()</span></span><br><span class="line">    log.Println(<span class="string">"------end："</span> + time.Now().String())</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br></pre></td></tr></table></figure></p>
<a id="more"></a>
<p>脚本处理入口 GoShell函数</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> shell</span><br><span class="line"></span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">GoShell</span><span class="params">()</span></span> &#123; </span><br><span class="line">    <span class="comment">// 初始化数据库以及索引</span></span><br><span class="line">    InitDbIndex()</span><br><span class="line">    <span class="comment">// 开始脚本处理，进行mapreduce计算，结果写入elasticSearch</span></span><br><span class="line">    MapReductAndSyncDataToEsMutilDay()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><code>MapReductAndSyncDataToEsMutilDay()</code></p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> shell</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line"><span class="comment">// 计算数据，以及把数据同步到ES</span></span><br><span class="line"><span class="comment">// 根据脚本传递的第一个参数，决定处理当前时间前n天的数据统计。</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">MapReductAndSyncDataToEsMutilDay</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">var</span> day <span class="keyword">int</span></span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(os.Args) &gt; <span class="number">1</span> &#123;</span><br><span class="line">        <span class="keyword">var</span> err error</span><br><span class="line">        day, err = helper.Int(os.Args[<span class="number">1</span>])</span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            log.Println(err.Error())</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> day == <span class="number">0</span> &#123;</span><br><span class="line">        day = <span class="number">1</span></span><br><span class="line">    &#125;</span><br><span class="line">    log.Println(<span class="string">"###########"</span>)</span><br><span class="line">    log.Println(day)</span><br><span class="line">    dateStr := helper.DateUTCStr()</span><br><span class="line">    timestamps := helper.GetTimestampsByDate(dateStr)</span><br><span class="line">    </span><br><span class="line">	<span class="comment">// 删除所有的elasticSearch Index, </span></span><br><span class="line">	<span class="comment">// 对于新建mapping部分，在计算脚本的时候，都会init相应的mapping</span></span><br><span class="line">	<span class="comment">// 譬如：对于./shell/advertise/eid.go 444行代码出：  esAdvertiseEidTypeMapping := helper.GetEsAdvertiseEidTypeMapping()</span></span><br><span class="line">	<span class="comment">// 因此删除原来的所有的es index，只需要将下面的</span></span><br><span class="line">	<span class="keyword">if</span> <span class="built_in">len</span>(os.Args) &gt; <span class="number">2</span> &#123;</span><br><span class="line">		operateType := os.Args[<span class="number">2</span>]</span><br><span class="line">		<span class="keyword">if</span> operateType == <span class="string">"removeEsAllIndex"</span> &#123;</span><br><span class="line">			log.Println(<span class="string">"begin remove es all index"</span>)</span><br><span class="line">			err := RemoveSpecialEsIndex()</span><br><span class="line">			<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">				log.Println(err.Error())</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> i:=<span class="number">0</span>; i &lt; day; i++ &#123;</span><br><span class="line">        preDayTimeStamps := timestamps - <span class="number">86400</span> * <span class="keyword">int64</span>(i)</span><br><span class="line">        preDateStr := helper.GetDateTimeUtcByTimestamps(preDayTimeStamps)</span><br><span class="line">        log.Println(preDateStr)</span><br><span class="line">        log.Println(<span class="string">"mapReduceByDate ... "</span>)</span><br><span class="line">        err := mapReduceByDate(preDateStr)</span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            log.Println(err.Error())</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; </span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br></pre></td></tr></table></figure>
<p>处理某一天的数据<br><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> shell</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line"><span class="comment">// 处理某一天的数据</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">mapReduceByDate</span><span class="params">(dateStr <span class="keyword">string</span>)</span> <span class="title">error</span></span>&#123;</span><br><span class="line">    <span class="keyword">var</span> err error</span><br><span class="line">    <span class="comment">// 通过时间，得到数据库name  例如：trace_2020_01_01</span></span><br><span class="line">    dbName := helper.GetTraceDbNameByDate(dateStr) </span><br><span class="line">    websiteInfos, err := commonHandler.GetAllActiveWebsites()</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 判断网站数量</span></span><br><span class="line">    <span class="keyword">if</span> WebsiteCount &lt; <span class="built_in">len</span>(websiteInfos) &#123;</span><br><span class="line">        <span class="keyword">return</span> errors.New(<span class="string">"website count is Limit Exceeded "</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> i:=<span class="number">0</span>; i&lt;<span class="built_in">len</span>(websiteInfos); i++ &#123;</span><br><span class="line">        websiteInfo := websiteInfos[i]</span><br><span class="line">        websiteId := websiteInfo.SiteUid</span><br><span class="line">        <span class="comment">//esIndexName := helper.GetEsIndexName(websiteId)</span></span><br><span class="line">        collName := helper.GetTraceDataCollName(websiteId)</span><br><span class="line">		log.Println(<span class="string">"websiteId:"</span>)</span><br><span class="line">		log.Println(websiteId)</span><br><span class="line">        log.Println(<span class="string">"###########"</span>)</span><br><span class="line">        log.Println(<span class="string">"OutWholeBrowserCollName"</span>)</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 判断数据的pv数，是否超出限制？</span></span><br><span class="line">		<span class="comment">// 不做数据限制</span></span><br><span class="line">		<span class="comment">/*</span></span><br><span class="line"><span class="comment">        collCount := 0</span></span><br><span class="line"><span class="comment">        err = mongodb.MDC(dbName, collName, func(coll *mgo.Collection) error &#123;</span></span><br><span class="line"><span class="comment">            collCount, err = coll.Count()</span></span><br><span class="line"><span class="comment">            return err</span></span><br><span class="line"><span class="comment">        &#125;)</span></span><br><span class="line"><span class="comment">        if collCount &gt; PvCount &#123;</span></span><br><span class="line"><span class="comment">            return errors.New("pv count is Limit Exceeded ")</span></span><br><span class="line"><span class="comment">        &#125;</span></span><br><span class="line"><span class="comment">		*/</span></span><br><span class="line">        </span><br><span class="line">        .</span><br><span class="line">        .</span><br><span class="line">        .</span><br><span class="line">        <span class="comment">// trace_whole_browser_data_&#123;websiteId&#125;</span></span><br><span class="line">        OutWholeBrowserCollName := helper.GetOutWholeBrowserCollName(websiteId)</span><br><span class="line">        err = whole.BrowserMapReduct(dbName, collName, OutWholeBrowserCollName, websiteId)</span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> err</span><br><span class="line">        &#125;</span><br><span class="line">        log.Println(<span class="string">"###########"</span>)</span><br><span class="line">        log.Println(<span class="string">"OutWholeAllCollName"</span>)</span><br><span class="line">        <span class="comment">// Whole All</span></span><br><span class="line">        OutWholeAllCollName := helper.GetOutWholeAllCollName(websiteId)</span><br><span class="line">        err = whole.AllMapReduct(dbName, collName, OutWholeAllCollName, websiteId)</span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> err</span><br><span class="line">        &#125;</span><br><span class="line">        log.Println(<span class="string">"###########"</span>)</span><br><span class="line">        log.Println(<span class="string">"OutWholeReferCollName"</span>)</span><br><span class="line">        .</span><br><span class="line">        .</span><br><span class="line">        .</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>whole.BrowserMapReduct()</code></p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> whole</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span>(</span><br><span class="line">    <span class="comment">// "github.com/fecshopsoft/fec-go/shell/whole"</span></span><br><span class="line">    <span class="comment">// "github.com/fecshopsoft/fec-go/util"</span></span><br><span class="line">    <span class="string">"github.com/fecshopsoft/fec-go/db/mongodb"</span></span><br><span class="line">    <span class="string">"github.com/fecshopsoft/fec-go/db/esdb"</span></span><br><span class="line">    <span class="string">"github.com/fecshopsoft/fec-go/helper"</span></span><br><span class="line">    <span class="string">"github.com/fecshopsoft/fec-go/shell/model"</span></span><br><span class="line">    <span class="string">"github.com/globalsign/mgo"</span></span><br><span class="line">    <span class="string">"github.com/globalsign/mgo/bson"</span></span><br><span class="line">    <span class="string">"math"</span></span><br><span class="line">    <span class="string">"log"</span></span><br><span class="line">    </span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器统计计算部分</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">BrowserMapReduct</span><span class="params">(dbName <span class="keyword">string</span>, collName <span class="keyword">string</span>, outCollName <span class="keyword">string</span>, website_id <span class="keyword">string</span>)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">    <span class="keyword">var</span> err error</span><br><span class="line">    mapStr := <span class="string">`</span></span><br><span class="line"><span class="string">        function() &#123;  </span></span><br><span class="line"><span class="string">            website_id = "`</span> + website_id + <span class="string">`";</span></span><br><span class="line"><span class="string">            browser_name = this.browser_name ? this.browser_name : null;</span></span><br><span class="line"><span class="string">            // login_email 	= this.login_email ? [this.login_email] : null;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            stay_seconds = this.stay_seconds ? this.stay_seconds : 0;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            // 跳出个数和退出个数</span></span><br><span class="line"><span class="string">            jump_out_count = 0;   //跳出</span></span><br><span class="line"><span class="string">            drop_out_count = 0;		//退出</span></span><br><span class="line"><span class="string">            // 最后一个页面</span></span><br><span class="line"><span class="string">            rate_pv = 0;</span></span><br><span class="line"><span class="string">            if(this.stay_seconds == 0)&#123;</span></span><br><span class="line"><span class="string">                // 如果这个页面是第一个访问的页面，则代表跳出</span></span><br><span class="line"><span class="string">                if(this.uuid_first_page == 1 )&#123;</span></span><br><span class="line"><span class="string">                    jump_out_count = 1;</span></span><br><span class="line"><span class="string">                &#125;else&#123;</span></span><br><span class="line"><span class="string">                    drop_out_count = 1;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                rate_pv = 1;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            devide 			= this.devide;</span></span><br><span class="line"><span class="string">            if(devide)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[devide] = 1;</span></span><br><span class="line"><span class="string">                devide 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                devide = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            // country_code</span></span><br><span class="line"><span class="string">            country_code 	= this.country_code;</span></span><br><span class="line"><span class="string">            if(country_code)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[country_code] = 1;</span></span><br><span class="line"><span class="string">                country_code 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                country_code = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            // operate</span></span><br><span class="line"><span class="string">            operate 		= this.operate ;</span></span><br><span class="line"><span class="string">            if(operate)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[operate] = 1;</span></span><br><span class="line"><span class="string">                operate 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                operate = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // fec_app</span></span><br><span class="line"><span class="string">            fec_app 		= this.fec_app ;</span></span><br><span class="line"><span class="string">            if(fec_app)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[fec_app] = 1;</span></span><br><span class="line"><span class="string">                fec_app 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                fec_app = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            resolution 		= this.resolution ;</span></span><br><span class="line"><span class="string">            if(resolution)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[resolution] = 1;</span></span><br><span class="line"><span class="string">                resolution 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                resolution = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            color_depth 		= this.color_depth ;</span></span><br><span class="line"><span class="string">            if(color_depth)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[color_depth] = 1;</span></span><br><span class="line"><span class="string">                color_depth 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                color_depth = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            language 		= this.fec_lang;</span></span><br><span class="line"><span class="string">            if(language)&#123;</span></span><br><span class="line"><span class="string">                b= &#123;&#125;;</span></span><br><span class="line"><span class="string">                b[language] = 1;</span></span><br><span class="line"><span class="string">                language 	= b;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                language = null;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            // first_page</span></span><br><span class="line"><span class="string">            first_page 		= this.uuid_first_page ? this.uuid_first_page : 0;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            // 该处进行了更正，不应该 first_visit_this_url ，而应该使用 uuid_first_page</span></span><br><span class="line"><span class="string">            is_return = 0;</span></span><br><span class="line"><span class="string">            uv = 0;</span></span><br><span class="line"><span class="string">            if(this.uuid_first_page == 1)&#123;</span></span><br><span class="line"><span class="string">                uv = 1;</span></span><br><span class="line"><span class="string">                is_return = this.is_return ? this.is_return : 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            if(this.ip_first_page == 1)&#123;</span></span><br><span class="line"><span class="string">                ip_count = 1;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                ip_count = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            service_date_str = this.service_date_str ? this.service_date_str : null;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            cart = this.cart ? this.cart : null;</span></span><br><span class="line"><span class="string">            order = this.order ? this.order : null;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            cart_count = 0;</span></span><br><span class="line"><span class="string">            order_count = 0;</span></span><br><span class="line"><span class="string">            order_no_count = 0;</span></span><br><span class="line"><span class="string">            success_order_count = 0;</span></span><br><span class="line"><span class="string">            success_order_no_count = 0;</span></span><br><span class="line"><span class="string">            order_amount = 0;</span></span><br><span class="line"><span class="string">            success_order_amount = 0;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            if(cart)&#123;</span></span><br><span class="line"><span class="string">                for(x in cart)&#123;</span></span><br><span class="line"><span class="string">                    one 		= cart[x];</span></span><br><span class="line"><span class="string">                    if(one &amp;&amp; one['qty'])&#123;</span></span><br><span class="line"><span class="string">                        //$sku 		= one['sku'];</span></span><br><span class="line"><span class="string">                        var skuqty = Number(one['qty'])</span></span><br><span class="line"><span class="string">                        skuqty = isNaN(skuqty) ? 0 : skuqty</span></span><br><span class="line"><span class="string">                        cart_count += skuqty;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            if(order &amp;&amp; order['invoice'] &amp;&amp; order['products'])&#123;</span></span><br><span class="line"><span class="string">                products = order['products'];</span></span><br><span class="line"><span class="string">                payment_status = order['payment_status'];</span></span><br><span class="line"><span class="string">                amount = order['amount'];</span></span><br><span class="line"><span class="string">                if(amount)&#123;</span></span><br><span class="line"><span class="string">                    order_amount = amount;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                order_no_count = 1;</span></span><br><span class="line"><span class="string">                if(payment_status == 'payment_confirmed')&#123;</span></span><br><span class="line"><span class="string">                    success_order_no_count = 1;</span></span><br><span class="line"><span class="string">                    if(amount)&#123;</span></span><br><span class="line"><span class="string">                        success_order_amount = amount;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                for(x in products)&#123;</span></span><br><span class="line"><span class="string">                    one = products[x];</span></span><br><span class="line"><span class="string">                    if(one &amp;&amp; one['qty'])&#123;</span></span><br><span class="line"><span class="string">                        qty = Number(one['qty']);</span></span><br><span class="line"><span class="string">                        qty = isNaN(qty) ? 0 : qty</span></span><br><span class="line"><span class="string">                        order_count += qty;</span></span><br><span class="line"><span class="string">                        if(payment_status == 'payment_confirmed')&#123;</span></span><br><span class="line"><span class="string">                            success_order_count += qty;</span></span><br><span class="line"><span class="string">                            </span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            if(this.browser_name)&#123;</span></span><br><span class="line"><span class="string">                is_return = Number(is_return);</span></span><br><span class="line"><span class="string">                is_return = isNaN(is_return) ? 0 : is_return</span></span><br><span class="line"><span class="string">                first_page = Number(first_page);</span></span><br><span class="line"><span class="string">                first_page = isNaN(first_page) ? 0 : first_page</span></span><br><span class="line"><span class="string">                emit(this.browser_name+"_"+service_date_str+"_"+website_id,&#123;</span></span><br><span class="line"><span class="string">                    browser_name:browser_name,</span></span><br><span class="line"><span class="string">                    pv:1,</span></span><br><span class="line"><span class="string">                    uv:uv,</span></span><br><span class="line"><span class="string">                    ip_count:ip_count,</span></span><br><span class="line"><span class="string">                    rate_pv:rate_pv,</span></span><br><span class="line"><span class="string">                    stay_seconds:stay_seconds,</span></span><br><span class="line"><span class="string">                    //customer_id:customer_id,</span></span><br><span class="line"><span class="string">                    jump_out_count:jump_out_count,</span></span><br><span class="line"><span class="string">                    drop_out_count:drop_out_count,</span></span><br><span class="line"><span class="string">                    devide:devide,</span></span><br><span class="line"><span class="string">                    country_code:country_code,</span></span><br><span class="line"><span class="string">                    </span></span><br><span class="line"><span class="string">                    cart_count:cart_count,</span></span><br><span class="line"><span class="string">                    order_count:order_count,</span></span><br><span class="line"><span class="string">                    success_order_count:success_order_count,</span></span><br><span class="line"><span class="string">                    success_order_no_count:success_order_no_count,</span></span><br><span class="line"><span class="string">                    order_no_count:order_no_count,</span></span><br><span class="line"><span class="string">                    order_amount:order_amount,</span></span><br><span class="line"><span class="string">                    success_order_amount:success_order_amount,</span></span><br><span class="line"><span class="string">                    operate:operate,</span></span><br><span class="line"><span class="string">                    fec_app:fec_app,</span></span><br><span class="line"><span class="string">                    resolution:resolution,</span></span><br><span class="line"><span class="string">                    color_depth:color_depth,</span></span><br><span class="line"><span class="string">                    language:language,</span></span><br><span class="line"><span class="string">                    is_return: is_return,</span></span><br><span class="line"><span class="string">                    first_page: first_page,</span></span><br><span class="line"><span class="string">                    service_date_str:service_date_str</span></span><br><span class="line"><span class="string">                    </span></span><br><span class="line"><span class="string">                &#125;);</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    `</span></span><br><span class="line">    </span><br><span class="line">    reduceStr := <span class="string">`</span></span><br><span class="line"><span class="string">        function(key,emits)&#123;</span></span><br><span class="line"><span class="string">            this_pv 				= 0;</span></span><br><span class="line"><span class="string">            this_rate_pv			= 0;</span></span><br><span class="line"><span class="string">            this_uv 				= 0;</span></span><br><span class="line"><span class="string">            this_ip_count 			= 0;</span></span><br><span class="line"><span class="string">            this_stay_seconds 		= 0;</span></span><br><span class="line"><span class="string">            this_jump_out_count		= 0;</span></span><br><span class="line"><span class="string">            this_drop_out_count		= 0 ;</span></span><br><span class="line"><span class="string">            this_service_date_str 	= null;</span></span><br><span class="line"><span class="string">            this_devide				= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_country_code		= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_browser_name		= null;</span></span><br><span class="line"><span class="string">            this_operate			= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_fec_app      			= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_is_return			= 0;</span></span><br><span class="line"><span class="string">            this_first_page			= 0;</span></span><br><span class="line"><span class="string">            this_resolution			= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_color_depth		= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_language			= &#123;&#125;;</span></span><br><span class="line"><span class="string">            this_cart_count				= 0;</span></span><br><span class="line"><span class="string">            this_order_count			= 0;	</span></span><br><span class="line"><span class="string">            this_success_order_count	= 0;</span></span><br><span class="line"><span class="string">            this_order_amount			= 0;</span></span><br><span class="line"><span class="string">            this_success_order_amount	= 0;</span></span><br><span class="line"><span class="string">            this_success_order_no_count	= 0;</span></span><br><span class="line"><span class="string">            this_order_no_count	= 0;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            for(var i in emits)&#123;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].cart_count)&#123;</span></span><br><span class="line"><span class="string">                    this_cart_count 			+= emits[i].cart_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].order_count)&#123;</span></span><br><span class="line"><span class="string">                    this_order_count 			+= emits[i].order_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].success_order_count)&#123;</span></span><br><span class="line"><span class="string">                    this_success_order_count 	+= emits[i].success_order_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].success_order_no_count)&#123;</span></span><br><span class="line"><span class="string">                    this_success_order_no_count += emits[i].success_order_no_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].order_no_count)&#123;</span></span><br><span class="line"><span class="string">                    this_order_no_count += emits[i].order_no_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].order_amount)&#123;</span></span><br><span class="line"><span class="string">                    this_order_amount 			+= emits[i].order_amount;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].success_order_amount)&#123;</span></span><br><span class="line"><span class="string">                    this_success_order_amount 	+= emits[i].success_order_amount;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].browser_name)&#123;</span></span><br><span class="line"><span class="string">                    this_browser_name = emits[i].browser_name;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].pv)&#123;</span></span><br><span class="line"><span class="string">                    this_pv 			+= emits[i].pv;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].uv)&#123;</span></span><br><span class="line"><span class="string">                    this_uv 			+= emits[i].uv;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].ip_count)&#123;</span></span><br><span class="line"><span class="string">                    this_ip_count 			+= emits[i].ip_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].stay_seconds)&#123;</span></span><br><span class="line"><span class="string">                    this_stay_seconds 	+= emits[i].stay_seconds;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].service_date_str)&#123;</span></span><br><span class="line"><span class="string">                    this_service_date_str = emits[i].service_date_str;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                //this_customer_id = this_customer_id.concat(emits[i].customer_id);</span></span><br><span class="line"><span class="string">                if(emits[i].jump_out_count)&#123;</span></span><br><span class="line"><span class="string">                    this_jump_out_count += emits[i].jump_out_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].drop_out_count)&#123;</span></span><br><span class="line"><span class="string">                    this_drop_out_count += emits[i].drop_out_count;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].rate_pv)&#123;</span></span><br><span class="line"><span class="string">                    this_rate_pv 		+= emits[i].rate_pv;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].devide)&#123;</span></span><br><span class="line"><span class="string">                    devide = emits[i].devide;</span></span><br><span class="line"><span class="string">                    for(brower_ne in devide)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = devide[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_devide[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_devide[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_devide[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].country_code)&#123;</span></span><br><span class="line"><span class="string">                    country_code = emits[i].country_code;</span></span><br><span class="line"><span class="string">                    for(brower_ne in country_code)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = country_code[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_country_code[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_country_code[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_country_code[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].operate)&#123;</span></span><br><span class="line"><span class="string">                    operate = emits[i].operate;</span></span><br><span class="line"><span class="string">                    for(brower_ne in operate)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = operate[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_operate[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_operate[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_operate[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].fec_app)&#123;</span></span><br><span class="line"><span class="string">                    fec_app = emits[i].fec_app;</span></span><br><span class="line"><span class="string">                    for(brower_ne in fec_app)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = fec_app[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_fec_app[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_fec_app[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_fec_app[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].resolution)&#123;</span></span><br><span class="line"><span class="string">                    resolution = emits[i].resolution;</span></span><br><span class="line"><span class="string">                    for(brower_ne in resolution)&#123;</span></span><br><span class="line"><span class="string">                        count = resolution[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_resolution[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_resolution[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_resolution[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].color_depth)&#123;</span></span><br><span class="line"><span class="string">                    color_depth = emits[i].color_depth;</span></span><br><span class="line"><span class="string">                    for(brower_ne in color_depth)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = color_depth[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_color_depth[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_color_depth[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_color_depth[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].language)&#123;</span></span><br><span class="line"><span class="string">                    language = emits[i].language;</span></span><br><span class="line"><span class="string">                    for(brower_ne in language)&#123;</span></span><br><span class="line"><span class="string">                        </span></span><br><span class="line"><span class="string">                        count = language[brower_ne];</span></span><br><span class="line"><span class="string">                        if(!this_language[brower_ne])&#123;</span></span><br><span class="line"><span class="string">                            this_language[brower_ne] = count;</span></span><br><span class="line"><span class="string">                        &#125;else&#123;</span></span><br><span class="line"><span class="string">                            this_language[brower_ne] += count;</span></span><br><span class="line"><span class="string">                        &#125;</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                </span></span><br><span class="line"><span class="string">                if(emits[i].is_return)&#123;</span></span><br><span class="line"><span class="string">                    this_is_return 			+= emits[i].is_return;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">                if(emits[i].first_page)&#123;</span></span><br><span class="line"><span class="string">                    this_first_page 		+= emits[i].first_page;</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            return &#123;	</span></span><br><span class="line"><span class="string">                browser_name:this_browser_name,</span></span><br><span class="line"><span class="string">                pv:this_pv,</span></span><br><span class="line"><span class="string">                uv:this_uv,</span></span><br><span class="line"><span class="string">                rate_pv:this_rate_pv,</span></span><br><span class="line"><span class="string">                jump_out_count:this_jump_out_count,</span></span><br><span class="line"><span class="string">                drop_out_count:this_drop_out_count,</span></span><br><span class="line"><span class="string">                stay_seconds:this_stay_seconds,</span></span><br><span class="line"><span class="string">                //customer_id:this_customer_id,</span></span><br><span class="line"><span class="string">                    </span></span><br><span class="line"><span class="string">                devide:this_devide,</span></span><br><span class="line"><span class="string">                country_code:this_country_code,</span></span><br><span class="line"><span class="string">                ip_count:this_ip_count,</span></span><br><span class="line"><span class="string">                operate:this_operate,</span></span><br><span class="line"><span class="string">                fec_app:this_fec_app,</span></span><br><span class="line"><span class="string">                is_return:this_is_return,</span></span><br><span class="line"><span class="string">                first_page:this_first_page,</span></span><br><span class="line"><span class="string">                resolution:this_resolution,</span></span><br><span class="line"><span class="string">                color_depth:this_color_depth,</span></span><br><span class="line"><span class="string">                language:this_language,</span></span><br><span class="line"><span class="string">                cart_count:this_cart_count,</span></span><br><span class="line"><span class="string">                order_count:this_order_count,	</span></span><br><span class="line"><span class="string">                success_order_count:this_success_order_count,</span></span><br><span class="line"><span class="string">                success_order_no_count:this_success_order_no_count,</span></span><br><span class="line"><span class="string">                order_no_count:this_order_no_count,</span></span><br><span class="line"><span class="string">                order_amount:this_order_amount,</span></span><br><span class="line"><span class="string">                success_order_amount:this_success_order_amount,</span></span><br><span class="line"><span class="string">                service_date_str:this_service_date_str</span></span><br><span class="line"><span class="string">            &#125;;</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    `</span></span><br><span class="line">    </span><br><span class="line">    finalizeStr := <span class="string">`</span></span><br><span class="line"><span class="string">        function (key, reducedVal) &#123;</span></span><br><span class="line"><span class="string">            uv = reducedVal.uv;</span></span><br><span class="line"><span class="string">            pv = reducedVal.pv;</span></span><br><span class="line"><span class="string">            // 平均pv</span></span><br><span class="line"><span class="string">            if(uv)&#123;</span></span><br><span class="line"><span class="string">                this_pv_rate = pv/uv;</span></span><br><span class="line"><span class="string">                this_pv_rate = this_pv_rate*10000;</span></span><br><span class="line"><span class="string">                this_pv_rate = Math.ceil(this_pv_rate);</span></span><br><span class="line"><span class="string">                this_pv_rate = this_pv_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_pv_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // 销售转换率</span></span><br><span class="line"><span class="string">            if(uv)&#123;</span></span><br><span class="line"><span class="string">                this_success_order_no_count = reducedVal.success_order_no_count;</span></span><br><span class="line"><span class="string">                this_sku_sale_rate = this_success_order_no_count/uv;</span></span><br><span class="line"><span class="string">                this_sku_sale_rate = this_sku_sale_rate*10000;</span></span><br><span class="line"><span class="string">                this_sku_sale_rate = Math.ceil(this_sku_sale_rate);</span></span><br><span class="line"><span class="string">                this_sku_sale_rate = this_sku_sale_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_sku_sale_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // 订单支付率</span></span><br><span class="line"><span class="string">            order_no_count = reducedVal.order_no_count;</span></span><br><span class="line"><span class="string">            if(order_no_count)&#123;</span></span><br><span class="line"><span class="string">                this_success_order_no_count = reducedVal.success_order_no_count;</span></span><br><span class="line"><span class="string">                this_order_payment_rate = this_success_order_no_count/order_no_count;</span></span><br><span class="line"><span class="string">                this_order_payment_rate = this_order_payment_rate*10000;</span></span><br><span class="line"><span class="string">                this_order_payment_rate = Math.ceil(this_order_payment_rate);</span></span><br><span class="line"><span class="string">                this_order_payment_rate = this_order_payment_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_order_payment_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // 跳出率</span></span><br><span class="line"><span class="string">            if(uv)&#123;</span></span><br><span class="line"><span class="string">                this_jump_out_count = reducedVal.jump_out_count;</span></span><br><span class="line"><span class="string">                this_jump_out_rate = this_jump_out_count/uv;</span></span><br><span class="line"><span class="string">                this_jump_out_rate = this_jump_out_rate*10000;</span></span><br><span class="line"><span class="string">                this_jump_out_rate = Math.ceil(this_jump_out_rate);</span></span><br><span class="line"><span class="string">                this_jump_out_rate = this_jump_out_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_jump_out_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // 退出率</span></span><br><span class="line"><span class="string">            if(uv)&#123;</span></span><br><span class="line"><span class="string">                this_drop_out_count = reducedVal.drop_out_count;</span></span><br><span class="line"><span class="string">                this_drop_out_rate = this_drop_out_count/uv;</span></span><br><span class="line"><span class="string">                this_drop_out_rate = this_drop_out_rate*10000;</span></span><br><span class="line"><span class="string">                this_drop_out_rate = Math.ceil(this_drop_out_rate);</span></span><br><span class="line"><span class="string">                this_drop_out_rate = this_drop_out_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_drop_out_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            // 老用户比率</span></span><br><span class="line"><span class="string">            if(uv)&#123;</span></span><br><span class="line"><span class="string">                this_is_return = reducedVal.is_return;</span></span><br><span class="line"><span class="string">                this_is_return_rate = (this_is_return/uv); </span></span><br><span class="line"><span class="string">                this_is_return_rate = this_is_return_rate*10000;</span></span><br><span class="line"><span class="string">                this_is_return_rate = Math.ceil(this_is_return_rate);</span></span><br><span class="line"><span class="string">                this_is_return_rate = this_is_return_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                this_is_return_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            reducedVal.is_return_rate= this_is_return_rate;</span></span><br><span class="line"><span class="string">            this_stay_seconds = reducedVal.stay_seconds;</span></span><br><span class="line"><span class="string">            //平均停留时间</span></span><br><span class="line"><span class="string">            rate_pv = reducedVal.rate_pv;</span></span><br><span class="line"><span class="string">            if(rate_pv)&#123;</span></span><br><span class="line"><span class="string">                stay_seconds_rate = (this_stay_seconds/rate_pv); </span></span><br><span class="line"><span class="string">                stay_seconds_rate = stay_seconds_rate*10000;</span></span><br><span class="line"><span class="string">                stay_seconds_rate = Math.ceil(stay_seconds_rate);</span></span><br><span class="line"><span class="string">                stay_seconds_rate = stay_seconds_rate/10000;</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                stay_seconds_rate = 0;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            reducedVal.stay_seconds_rate = stay_seconds_rate;</span></span><br><span class="line"><span class="string">            reducedVal.jump_out_rate     = this_jump_out_rate;</span></span><br><span class="line"><span class="string">            reducedVal.drop_out_rate     = this_drop_out_rate;</span></span><br><span class="line"><span class="string">            reducedVal.sku_sale_rate     = this_sku_sale_rate;</span></span><br><span class="line"><span class="string">            reducedVal.order_payment_rate= this_order_payment_rate;</span></span><br><span class="line"><span class="string">            //reducedVal.country_code    = this_country_code;</span></span><br><span class="line"><span class="string">            //reducedVal.browser_name    = this_browser_name;</span></span><br><span class="line"><span class="string">            //reducedVal.operate 		 = this_operate;</span></span><br><span class="line"><span class="string">            reducedVal.pv_rate		     = this_pv_rate;</span></span><br><span class="line"><span class="string">            reducedVal.website_id        = "`</span> + website_id + <span class="string">`"</span></span><br><span class="line"><span class="string">            </span></span><br><span class="line"><span class="string">            return reducedVal;</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    `</span></span><br><span class="line">    <span class="comment">// 结果输出的 mongodb collection</span></span><br><span class="line">    outDoc := bson.M&#123;<span class="string">"replace"</span>: outCollName&#125;</span><br><span class="line">    <span class="comment">// 执行mapreduce的job struct</span></span><br><span class="line">    job := &amp;mgo.MapReduce&#123;</span><br><span class="line">        Map:      mapStr,</span><br><span class="line">        Reduce:   reduceStr,</span><br><span class="line">        Finalize: finalizeStr,</span><br><span class="line">        Out:      outDoc,</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 开始执行map reduce</span></span><br><span class="line">    err = mongodb.MDC(dbName, collName, <span class="function"><span class="keyword">func</span><span class="params">(coll *mgo.Collection)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">        _, err := coll.Find(<span class="literal">nil</span>).MapReduce(job, <span class="literal">nil</span>)</span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 上面mongodb maoreduce处理完的数据，需要存储到es中</span></span><br><span class="line">    <span class="comment">// 得到 type 以及 index name</span></span><br><span class="line">    esWholeBrowserTypeName :=  helper.GetEsWholeBrowserTypeName()</span><br><span class="line">    esIndexName := helper.GetEsIndexNameByType(esWholeBrowserTypeName)</span><br><span class="line">    <span class="comment">// es index 的type mapping</span></span><br><span class="line">    esWholeBrowserTypeMapping := helper.GetEsWholeBrowserTypeMapping()</span><br><span class="line">    <span class="comment">// 删除index，如果mapping建立的不正确，可以执行下面的语句删除重建mapping</span></span><br><span class="line">    <span class="comment">//err = esdb.DeleteIndex(esIndexName)</span></span><br><span class="line">    <span class="comment">//if err != nil &#123;</span></span><br><span class="line">    <span class="comment">//    return err</span></span><br><span class="line">    <span class="comment">//&#125;</span></span><br><span class="line">    <span class="comment">// 初始化mapping</span></span><br><span class="line">    err = esdb.InitMapping(esIndexName, esWholeBrowserTypeName, esWholeBrowserTypeMapping)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 同步mongo数据到ES</span></span><br><span class="line">    <span class="comment">// mongodb中的数据总数</span></span><br><span class="line">    mCount := <span class="number">0</span></span><br><span class="line">    <span class="comment">// 得到总数</span></span><br><span class="line">    err = mongodb.MDC(dbName, outCollName, <span class="function"><span class="keyword">func</span><span class="params">(coll *mgo.Collection)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">        <span class="keyword">var</span> err error</span><br><span class="line">        mCount, err = coll.Count() </span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> err</span><br><span class="line">    &#125;</span><br><span class="line">    numPerPage := helper.BulkSyncCount</span><br><span class="line">    pageNum := <span class="keyword">int</span>(math.Ceil(<span class="keyword">float64</span>(mCount) / <span class="keyword">float64</span>(numPerPage)))</span><br><span class="line">    <span class="keyword">for</span> i:=<span class="number">0</span>; i&lt;pageNum; i++ &#123;</span><br><span class="line">        err = mongodb.MDC(dbName, outCollName, <span class="function"><span class="keyword">func</span><span class="params">(coll *mgo.Collection)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">            <span class="keyword">var</span> err error</span><br><span class="line">            <span class="keyword">var</span> wholeBrowsers []model.WholeBrowser</span><br><span class="line">            coll.Find(<span class="literal">nil</span>).Skip(i*pageNum).Limit(numPerPage).All(&amp;wholeBrowsers)</span><br><span class="line">            log.Println(<span class="string">"wholeBrowsers length:"</span>)</span><br><span class="line">            log.Println(<span class="built_in">len</span>(wholeBrowsers))</span><br><span class="line">            </span><br><span class="line">            <span class="comment">/* 这个代码是upsert单行数据</span></span><br><span class="line"><span class="comment">            for j:=0; j&lt;len(wholeBrowsers); j++ &#123;</span></span><br><span class="line"><span class="comment">                wholeBrowser := wholeBrowsers[j]</span></span><br><span class="line"><span class="comment">                wholeBrowserValue := wholeBrowser.Value</span></span><br><span class="line"><span class="comment">                // wholeBrowserValue.Devide = nil</span></span><br><span class="line"><span class="comment">                // wholeBrowserValue.CountryCode = nil</span></span><br><span class="line"><span class="comment">                ///wholeBrowserValue.Operate = nil</span></span><br><span class="line"><span class="comment">                log.Println("ID_:" + wholeBrowser.Id_)</span></span><br><span class="line"><span class="comment">                wholeBrowserValue.Id = wholeBrowser.Id_</span></span><br><span class="line"><span class="comment">                err := esdb.UpsertType(esIndexName, esWholeBrowserTypeName, wholeBrowser.Id_, wholeBrowserValue)</span></span><br><span class="line"><span class="comment">                </span></span><br><span class="line"><span class="comment">                if err != nil &#123;</span></span><br><span class="line"><span class="comment">                    log.Println("11111" + err.Error())</span></span><br><span class="line"><span class="comment">                    return err</span></span><br><span class="line"><span class="comment">                &#125;</span></span><br><span class="line"><span class="comment">            &#125;</span></span><br><span class="line"><span class="comment">            */</span></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(wholeBrowsers) &gt; <span class="number">0</span> &#123;</span><br><span class="line">                <span class="comment">// 使用bulk的方式，将数据批量插入到elasticSearch</span></span><br><span class="line">                bulkRequest, err := esdb.Bulk()</span><br><span class="line">                <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">                    log.Println(<span class="string">"444"</span> + err.Error())</span><br><span class="line">                    <span class="keyword">return</span> err</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">for</span> j:=<span class="number">0</span>; j&lt;<span class="built_in">len</span>(wholeBrowsers); j++ &#123;</span><br><span class="line">                    wholeBrowser := wholeBrowsers[j]</span><br><span class="line">                    wholeBrowserValue := wholeBrowser.Value</span><br><span class="line">                    wholeBrowserValue.Id = wholeBrowser.Id_</span><br><span class="line">                    log.Println(<span class="string">"888"</span>)</span><br><span class="line">                    log.Println(esIndexName)</span><br><span class="line">                    log.Println(esWholeBrowserTypeName)</span><br><span class="line">                    log.Println(wholeBrowser.Id_)</span><br><span class="line">                    log.Println(wholeBrowserValue)</span><br><span class="line">                    req := esdb.BulkUpsertTypeDoc(esIndexName, esWholeBrowserTypeName, wholeBrowser.Id_, wholeBrowserValue)</span><br><span class="line">                    bulkRequest = bulkRequest.Add(req)</span><br><span class="line">                &#125;</span><br><span class="line">                bulkResponse, err := esdb.BulkRequestDo(bulkRequest)</span><br><span class="line">                <span class="comment">// bulkResponse, err := bulkRequest.Do()</span></span><br><span class="line">                <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">                    log.Println(<span class="string">"#############3"</span>)</span><br><span class="line">                    log.Println(<span class="string">"333"</span> + err.Error())</span><br><span class="line">                    <span class="keyword">return</span> err</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> bulkResponse != <span class="literal">nil</span> &#123;</span><br><span class="line">                    log.Println(<span class="string">"#############4"</span>)</span><br><span class="line">                    log.Println(bulkResponse)</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> err</span><br><span class="line">        &#125;)</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            log.Println(<span class="string">"##############5"</span> + err.Error())</span><br><span class="line">            <span class="keyword">return</span> err</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        log.Println(<span class="string">"#############6"</span> + err.Error())</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> err</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">type MapReduce struct &#123;</span></span><br><span class="line"><span class="comment">    Map      string      // Map Javascript function code (required)</span></span><br><span class="line"><span class="comment">    Reduce   string      // Reduce Javascript function code (required)</span></span><br><span class="line"><span class="comment">    Finalize string      // Finalize Javascript function code (optional)</span></span><br><span class="line"><span class="comment">    Out      interface&#123;&#125; // Output collection name or document. If nil, results are inlined into the result parameter.</span></span><br><span class="line"><span class="comment">    Scope    interface&#123;&#125; // Optional global scope for Javascript functions</span></span><br><span class="line"><span class="comment">    Verbose  bool</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">type resultValue struct&#123;</span></span><br><span class="line"><span class="comment">    BrowserNameCount int64 `browser_name`</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">var result []struct &#123; </span></span><br><span class="line"><span class="comment">    Id string `_id`</span></span><br><span class="line"><span class="comment">    Value resultValue </span></span><br><span class="line"><span class="comment">&#125; dbName string, collName string, outCollName</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<p>未完待续…</p>

      
    </div>

    

    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">------本文结束<i class="fa fa-paw"></i>感谢阅读------</div>
    
</div>
  
</div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>欣赏此文？求鼓励，求支持！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="云舒 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="云舒 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>云舒</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://blog.yunshu168.com/posts/6e943b7a.html" title="FA 用户数据分析系统学习笔记">http://blog.yunshu168.com/posts/6e943b7a.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/f5f4aa82.html" rel="next" title="fecshop开源商城学习笔记">
                <i class="fa fa-chevron-left"></i> fecshop开源商城学习笔记
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/f018699e.html" rel="prev" title="krpano学习笔记">
                krpano学习笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="云舒" />
            
              <p class="site-author-name" itemprop="name">云舒</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives">
                
                    <span class="site-state-item-count">68</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">5</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">28</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/yunshu2009" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yunshu.luo@gmail.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.cnblogs.com/luoyunshu/" target="_blank" title="Cnblogs"><i class="fa fa-fw fa-globe"></i>Cnblogs</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.bilibili.com" target="_blank" title="bilibili"><i class="fa fa-fw fa-globe"></i>bilibili</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#数据统计"><span class="nav-number">1.</span> <span class="nav-text">数据统计</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2012 &mdash; <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">云舒</span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Pisces</a></div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.4"></script>



  



	





  





  






<!-- LOCAL: You can save these files to your site and update links -->
    
        
         <!-- <link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css"> -->
        <!-- <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script> -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/theme-next/theme-next-gitment@1/default.css">
        <script src="https://cdn.jsdelivr.net/gh/theme-next/theme-next-gitment@1/gitment.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitment({
            id: decodeURI(window.location.pathname),
            owner: 'yunshu2009',
            repo: 'yunshu2009.github.io',
            
            oauth: {
            
            
                client_secret: '15cdd9dc30fb9e0c97260bf79fe09d158fa04b22',
            
                client_id: '9495da16cda475a5e221'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  
  

  

  

  

  


</body>
</html>
